<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>设备转移管理</title>
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <script src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script type="text/javascript" src="../../js/jquery/jquery-1.9.1.js"></script>
    <script src="../../js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/baseCode/base.js?v=201908121454" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/common.js?v=201907231346" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../lib/ueditor/ueditor.config.js" type="text/javascript" charset="utf-8"></script>
    <script src="../lib/ueditor/ueditor.all.js" type="text/javascript" charset="utf-8"></script>

    <style>
        .mbox {
            padding: 8px;
        }
        .layui-btn {
            margin-left: 10px;
        }
        .layui-btn .layui-icon {
            margin-right: 0px;
        }

        .layui-card-body {
            display: flex;
            padding: 0px;
        }
        .bg{
            background-color: #F2F2F2;
        }
        .layui-rt {
            width: 100%;
        }
        .layui-form-select .layui-input{
            height: 32px;
        }
        .layui-tab-title{
            height: 32px;
        }

        .layui-tab-title li{
            height: 33px;
            line-height: 33px;
        }
        .layui-tab layui-tab-card{
            margin-top: -4px;
        }
        .layui-tab-card>.layui-tab-title .layui-this:after {
            border-width: 0px;
        }
        .layui-table{
            margin-top: -2px !important;
        }
        .layui-table-view .layui-table td, .layui-table-view .layui-table th{
            padding: 2px 0;
        }
        #infoId td{
            padding: 5px 2px;
        }
        .tablecolor{
            background-color:#f2f2f2;
        }
        .layui-table{
            width:100%!important;
        }
        .layui-treeSelect .ztree li span.button.switch{
            top: 0!important;
        }
    </style>
</head>
<body>
<div class="mbox">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-rt">
                <div class="layui-tab layui-tab-card" lay-filter="tabtoggle">
                    <ul class="layui-tab-title">
                        <li class="layui-this">设备接收</li>
                    </ul>
                    <%--页签下面内容--%>
                    <div class="layui-tab-content" style="height:100%;padding: 0 10px 10px 10px">
                        <div class="layui-tab-item layui-show">
                            <table class="layui-table" lay-skin="line" id="Settlement" lay-size="sm" lay-filter="SettlementFilter"></table>
                            <div class="layui-tab layui-tab-card" lay-filter="bottomTab" style="position: relative;z-index: 0;margin-top: 15px">
                                <ul class="layui-tab-title">
                                    <li class="layui-this">转移设备明细</li>
                                </ul>
                                <div class="layui-tab-content" style="padding: 0 10px">
                                    <div class="layui-tab-item layui-show">
                                        <table id="transferDetail" lay-filter="transferFilter" lay-size="sm"> </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%--报废申请新增/删除撤销/查询字段--%>
<script type="text/html" id="toolbar">
    <%--<div class="layui-btn-container">--%>
        <%--<button class="layui-btn layui-btn-sm" lay-event="approval" style="width: 70px">批准</button>--%>
        <%--<button class="layui-btn layui-btn-sm" lay-event="disApproval" style="width: 100px">不批准</button>--%>
    <%--</div>--%>
    <div class="demoTable" style="position:absolute;right: 8%;top: 10px;width: 600px;height: 30px">
        <label style="float: left;width: 60px;">查询字段</label>
        <div class="layui-input-inline" style="float:left;">
            <select name="modules" lay-verify="required" lay-filter="serachInfo"lay-search="" placeholder="请选择" style="height: 10px">
                <option value="0">请选择查询字段</option>
                <option value="TRANSFER_DATE">调拨日期</option>
                <option value="ORIGINAL_DEPT_ID">原部门</option>
                <option value="ORIGINAL_CUSTODIAN">原保管人</option>
                <option value="NEW_DEPT_ID">新部门</option>
                <option value="NEW_CUSTODIAN">新保管人</option>
                <option value="APPLICATION">申请人</option>
                <option value="APPLICATION_TIME">流水号</option>
                <option value="APPROVER">审批人</option>
                <option value="APPROVER_TIME">审批时间</option>
                <option value="RECEIVE_STATUS">接收状态</option>
            </select>
        </div>
        <div style="float: left">
            <div class="layui-inline">
                <input class="layui-input" name="searchtext"  autocomplete="off" style="height: 32px;margin-left: 6px;">
            </div>
            <button class="layui-btn" data-type="reload"   lay-event="searchCust" style="height:30px;line-height: 30px; ">搜索</button>
        </div>
    </div>
</script>
<%--借还申请上头部--%>

<script type="text/html" id="barOperation">
    <a  class="layui-btn layui-btn-xs" style="{{d.receiveStatus==2 ? 'display:none' : ''}}" lay-event="resive" id="sub">接收</a>
</script>
<script type="text/javascript">
    var settlementTable,
        transferDetail;
    var ownerlogId;
    var logId;
    var col = [[
        {type: 'checkbox'}
        ,{field: 'receiveStatus', title: '接收状态',templet: function(d) {
                if (d.receiveStatus == "0") {
                    return '未接收'
                } else if (d.receiveStatus == "1") {
                    return '已接收'
                }
            }}
        , {field: 'equipName', title: '设备名称'}
        , {field: 'equipNo', title: '固定资产编号'}
        , {field: 'factoryNo', title: '出厂编号'}
        , {field: 'equipTypeName', title: '设备类型'}
        , {field: 'equipStatuasName', title: '资产状态'}
        , {field: 'modelNo', title: '型号'}
        , {field: 'spec', title: '规格'}
        ,{field: 'originalPositionName', title: '原存放位置'}
        ,{field: 'newPositionName', title: '新存放位置'}
        ,{field: 'userName', title: '接收人'}
        ,{field: 'receiveTime', title: '接收时间'}
        ,{field: 'memo', title: '备注'}
        , {width: 120, title: '操作', align: 'center', toolbar: '#barOperation'}
    ]];
    layui.use(['table', 'layer','laydate', 'form', 'element','treeSelect'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var element = layui.element;
        var laydate = layui.laydate;
        var treeSelect = layui.treeSelect;

        //报废申请表格实例
        settlementTable = table.render({
            elem: '#Settlement'
            , page: true //开启分页
            , url: '/equipTransfer/selectRceInfo'//数据接口
            , toolbar: '#toolbar'
            , cols: [[ //标题栏
                {type: 'checkbox'}
                ,{field: 'receiveStatus', title: '接收状态',templet: function(d) {
                        if (d.receiveStatus == "0") {
                            return '未接收'
                        } else if (d.receiveStatus == "1") {
                            return '部分接收'
                        } else if(d.receiveStatus == "2"){
                            return '已接收'
                        }
                    }}
                , {field: 'transferDate', title: '调拨日期'}
                , {field: 'oldDeptName', title: '原部门'}
                , {field: 'originalCustodian', title: '原保管人'}
                , {field: 'newDeptName', title: '新部门'}
                , {field: 'newCustodianName', title: '新保管人'}
                , {field: 'applicationName', title: '申请人'}
                , {field: 'applicationTime', title: '申请时间'}
                , {field: 'applicationName', title: '审批人'}
                , {field: 'applicationTime', title: '审批时间'}
                , {field: 'workflowNo', title: '流水号'}
                , {width: 120, title: '操作', align: 'center', toolbar: '#barOperation'}
            ]],
            done: function (res) {
                // if (res.data.length > 0) {
                //     var ownerlogId = res.data[0].ownerlogId;
                //     equipTable("#transferDetail", ownerlogId, "#toolbars", col);
                // } else {
                //     cequipTable("#transferDetail", "#", col);
                // }
            }
        });
        transferDetail = table.render({
            elem: "#transferDetail"
            ,data:[]
            , url: ''
            , page: true //开启分页
            , limit: 5 //每页默认显示的数量
            , limits: [5, 10, 15, 20, 25, 30]
            , cols: [[
                {type: 'checkbox'}
                ,{field: 'receiveStatus', title: '接收状态',templet: function(d) {
                        if (d.receiveStatus == "0") {
                            return '未接收'
                        } else if (d.receiveStatus == "1") {
                            return '已接收'
                        }
                    }}
                , {field: 'equipName', title: '设备名称'}
                , {field: 'equipNo', title: '固定资产编号'}
                , {field: 'factoryNo', title: '出厂编号'}
                , {field: 'equipTypeName', title: '设备类型'}
                , {field: 'equipStatuasName', title: '资产状态'}
                , {field: 'modelNo', title: '型号'}
                , {field: 'spec', title: '规格'}
                ,{field: 'originalPositionName', title: '原存放位置'}
                ,{field: 'newPositionName', title: '新存放位置'}
                ,{field: 'userName', title: '接收人'}
                ,{field: 'receiveTime', title: '接收时间'}
                ,{field: 'memo', title: '备注'}
                , {width: 120, title: '操作', align: 'center', toolbar: '#barOperation'}
            ]],
        });

        table.on('toolbar(SettlementFilter)', function (obj) {
            var layEvent = obj.event;
            switch (layEvent) {
                case 'searchCust':
                    var inptext=$(".demoTable input[name='searchtext']").val();
                    var seletext=$(".demoTable").find("dl dd.layui-this").attr("lay-value");
                    if((inptext == "")&&(seletext==undefined)){
                        layer.msg("请输入需要搜索的条件");
                        return false;
                    }else if((inptext=="")&&(seletext!=undefined)){
                        layer.msg("请输入需要查询的条件");
                        return false;
                    }else if((inptext!="")&&(seletext==undefined)){
                        layer.msg("请选择查询的字段");
                        return false;
                    }else{
                        var datas={
                            inptext:inptext,
                            column:seletext
                        }
                        searchCusInfo(datas)
                    }
                    break;
            }
        });
        //监听第一实例表格行单击事件
        table.on('row(SettlementFilter)', function (obj) {
            var tr = obj.tr //得到当前行元素对象
            var data = obj.data //得到当前行数据
            ownerlogId = data.ownerlogId
            //选中行变颜色方法
            var index = $(this).attr('data-index');
            var tr = $(this).parent().children(tr);
            $(this).addClass("bg");
            for (var i = 0; i < tr.length; i++) {
                if (index != i) {
                    tr.eq(i).removeClass("bg");
                }
            }
            transferDetail.reload({
                url: '/equipTransfer/findBylogId?ownerlogId='+data.ownerlogId
            })
        });
        // 设备接收行内操作事件
        table.on('tool(SettlementFilter)', function (obj) {
            var data = obj.data; //获得当前行数据
            logId = data.ownerlogId;
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (layEvent === 'resive') {
                if(data.receiveStatus == "2"){
                    layer.msg("下面设备已经全部接收。");
                    return false;
                }else {
                    var newPositionName = $("#tre").find("a.curSelectedNode").attr("title");

                    var receiveStatus = "1";
                    $.ajax({
                        url: '/equipTransfer/updRecStatus',
                        method: 'post',
                        data: {
                            newPositionName: newPositionName,
                            ownerlogId: data.ownerlogId,
                            ownerlistId:data.ownerlistId,
                            receiveStatus: receiveStatus,
                        },
                        dataType: 'JSON',
                        success: function (res) {
                            if (res.code == 0) {
                                layer.msg(res.msg);
                                settlementTable.reload();
                                transferDetail.reload({
                                    url: '/equipTransfer/findBylogId?ownerlogId='+data.ownerlogId
                                })
                            } else {
                                layer.msg(res.msg);
                            }
                        }
                    });
                 /*   layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['500px', '360px'], //宽高
                    title: '接收',
                    maxmin: true,
                    btnAlign: 'c',
                    btn: ['确定', '关闭'],
                    content: '<form class="layui-form"  lay-filter="formTest" >' +
                    '<div class="one" id="PositionName"><div class="layui-form-item" style="margin: 20px 0;"><label class="layui-form-label" style="width: 150px;">新存放位置：</label><div class="layui-input-inline" id="tre" style="width: 200px;">' +
                    '<input type="text" name="clientLiable"  placeholder="请输入" id="clientLiable" lay-filter="clientLiable" class="layui-input">'+
                    '<input name="client" type="hidden" class="client" id="client"></div></div></div>'+
                    '<div class="one"><div class="layui-form-item"><label class="layui-form-label" style="width: 150px;">备注：</label><div class="layui-input-inline" style="width: 200px;">' +
                    '<input placeholder="请输入" id="memo" style="color:#888;height: 32px;" type="text" name="memo" autocomplete="off" class="layui-input"></div></div></div>' +
                    '</form>',
                    success: function (res) {
                        treeSelects(data.ownerlogId);
                        form.render();
                    }
                    , yes: function (index, layero) {
                        layer.close(index);
                        var newPositionId = $("#client").val();
                        var newPositionName = $("#tre").find("a.curSelectedNode").attr("title");
                        var memo = $("#memo").val();
                        var receiveStatus = "1";
                        $.ajax({
                            url: '/equipTransfer/updRecStatus',
                            method: 'post',
                            data: {
                                newPositionId: newPositionId,
                                newPositionName: newPositionName,
                                ownerlogId: data.ownerlogId,
                                receiveStatus: receiveStatus,
                                memo: memo
                            },
                            dataType: 'JSON',
                            success: function (res) {
                                if (res.code == 0) {
                                    layer.msg(res.msg);
                                    settlementTable.reload();
                                    transferDetail.reload({
                                        url: '/equipTransfer/findBylogId?ownerlogId='+data.ownerlogId
                                    })
                                } else {
                                    layer.msg(res.msg);
                                }
                            }
                        });
                    }
                    });*/
                }
            }
        });
        // 设备接收行内操作事件
        table.on('tool(transferFilter)', function (obj) {
            var data = obj.data; //获得当前行数据
            var positionId = data.positionId;
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (layEvent === 'resive') {
                if(data.receiveStatus == "0"){
                    var newPositionName = $("#tre").find("a.curSelectedNode").attr("title");

                    var receiveStatus = "1";
                    $.ajax({
                        url: '/equipTransfer/updRecStatus',
                        method: 'post',
                        data: {
                            newPositionName: newPositionName,
                            ownerlogId: data.ownerlogId,
                            ownerlistId:data.ownerlistId,
                            receiveStatus: receiveStatus,
                        },
                        dataType: 'JSON',
                        success: function (res) {
                            if (res.code == 0) {
                                layer.msg(res.msg);
                                settlementTable.reload();
                                transferDetail.reload({
                                    url: '/equipTransfer/findBylogId?ownerlogId='+data.ownerlogId
                                })
                            } else {
                                layer.msg(res.msg);
                            }
                        }
                    });
               /*     layer.open({
                        type: 1,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['500px', '360px'], //宽高
                        title: '接收',
                        maxmin: true,
                        btnAlign: 'c',
                        btn: ['确定', '关闭'],
                        content: '<form class="layui-form"  lay-filter="formTest" >' +
                        '<div class="one" id="PositionName"><div class="layui-form-item" style="margin: 20px 0;"><label class="layui-form-label" style="width: 150px;">新存放位置：</label><div class="layui-input-inline" style="width: 200px;" id="tree">' +
                        '<input type="text" name="clientLiable"  placeholder="请输入" id="clientLiable" lay-filter="clientLiable" class="layui-input">'+
                        '<input name="client" type="hidden" class="client" id="client"></div></div></div>'+
                        '<div class="one"><div class="layui-form-item"><label class="layui-form-label" style="width: 150px;">备注：</label><div class="layui-input-inline" style="width: 200px;">' +
                        '<input placeholder="请输入" id="memo" style="color:#888;height: 32px;" type="text" name="memo" autocomplete="off" class="layui-input"></div></div></div>' +
                        '</form>',
                        success: function (res) {
                            treeSelects(data.ownerlogId);
                            form.render();
                        }
                        , yes: function (index, layero) {
                            layer.close(index);
                           // var newPositionId = $("#client").val();
                            var newPositionName = $("#tre").find("a.curSelectedNode").attr("title");
                         //   var memo = $("#memo").val();
                            var receiveStatus = "1";
                            $.ajax({
                                url: '/equipTransfer/updRecStatus',
                                method: 'post',
                                data: {
                                     newPositionName: newPositionName,
                                    ownerlogId: data.ownerlogId,
                                    ownerlistId:data.ownerlistId,
                                    receiveStatus: receiveStatus,
                                 },
                                dataType: 'JSON',
                                success: function (res) {
                                    if (res.code == 0) {
                                        layer.msg(res.msg);
                                        settlementTable.reload();
                                        transferDetail.reload({
                                            url: '/equipTransfer/findBylogId?ownerlogId='+data.ownerlogId
                                        })
                                    } else {
                                        layer.msg(res.msg);
                                    }
                                }
                            });
                        }
                    });*/
                }else{
                    layer.msg("该设备已经接收");
                    return false;
                }
            }
        });
        function treeSelects(logid){
            treeSelect.render({
                // 选择器
                elem: '#clientLiable',
                // 数据
                data: '/equipTransfer/reciviList?ownerlogId='+logid,
                // 异步加载方式：get/post，默认get
                type: 'get',
                // 占位符
                placeholder: '请选择',
                // 是否开启搜索功能：true/false，默认false
                search: true,
                // 一些可定制的样式
                style: {
                    folder: {
                        enable: true
                    },
                    line: {
                        enable: true
                    }
                },
                // 点击回调
                click: function(d){
                    $('input[name="client"]').val(d.current.id);
                    form.render()

                },
                // 加载完成后的回调函数
                success: function (d) {
                    form.render()
                }
            });
        }
        //模糊查询
        function searchCusInfo(data) {
            var parm={}
            var toolb;
            var clo;
            var tableName;
            // var url="/equipTransfer/adminastorList"
            var url="/equipTransfer/selectRceInfo"
                parm = {
                    column: data.column,
                    inptext: data.inptext
                }
                $.ajax({
                    type: 'post'
                    ,url:url
                    , data: parm
                    , dataType: 'json',
                    success: function (res) {
                        var datas = res.data;
                        layui.table.render({
                            elem: '#Settlement'
                            , url: ''
                            ,data:datas
                            , page: true //开启分页
                            , toolbar: '#toolbar'
                            , limit: 5 //每页默认显示的数量
                            , limits: [5, 10, 15, 20, 25, 30]
                            , cols: [[ //标题栏
                                {type: 'checkbox'}
                                , {field: 'transferDate', title: '调拨日期'}
                                , {field: 'oldDeptName', title: '原部门'}
                                , {field: 'originalCustodian', title: '原保管人'}
                                , {field: 'newDeptName', title: '新部门'}
                                , {field: 'newCustodianName', title: '新保管人'}
                                , {field: 'applicationName', title: '申请人'}
                                , {field: 'applicationTime', title: '申请时间'}
                                , {field: 'applicationName', title: '审批人'}
                                , {field: 'applicationTime', title: '审批时间'}
                                , {field: 'workflowNo', title: '流水号'}
                                , {width: 200, title: '操作', align: 'center', toolbar: '#barOperation'}
                            ]],
                            done: function (res) {
                                if (res.data.length > 0) {
                                    var ownerlogId = res.data[0].ownerlogId;
                                    equipTable("#transferDetail", ownerlogId, "#toolbars", col);
                                } else {
                                    cequipTable("#transferDetail", "#", col);
                                }
                                // $("#" + searchColum + "").val($("#" + searchColum + "").val())
                                // $("#colum").find('option[value="' + searchColum + '"]').prop('selected', 'selected');
                                $(".demoTable input[name='searchtext']").val(data.inptext);
                                $(".demoTable").find("select[name='modules']").each(function () {
                                    // this代表的是<option></option>，对option再进行遍历
                                    $(this).children("option").each(function () {
                                        // 判断需要对那个选项进行回显
                                        if (this.value == data.column) {
                                            // 进行回显
                                            $(this).attr("selected", "selected");
                                        }
                                    });
                                })
                                layui.form.render('select');
                            }
                        });
                    }
                })

        }
    });
    // 批准选人操作
    function Xrtransfer(res){
        var newuserId = res.userId;
        var newuserName = res.userName;
        var data = layui.table.checkStatus('Settlement').data;
        var logIds = "";
        var approvalStatus = "2";
        for (var i = 0; i < data.length; i++) {
            logIds += data[i].ownerlogId + ",";
        }
        $.ajax({
            type: "post",
            url: "/equipTransfer/updStatus",
            dataType: "json",
            data: {
                logIds: logIds,
                recUser:newuserId,
                approvalStatus:approvalStatus
            },
            success: function (res) {
                if (res.code == 0) {
                    layer.msg(res.msg);
                    settlementTable.reload();
                } else {
                    layer.msg(res.msg);
                }
            }
        })
    }
    // 批准选人行内操作
    function Xrhntransfer(res){
        var newuserId = res.userId;
        var newuserName = res.userName;
        var logIds = ownerlogId + ",";
        var approvalStatus = "2";
        $.ajax({
            type: "post",
            url: "/equipTransfer/updStatus",
            dataType: "json",
            data: {
                logIds: logIds,
                recUser:newuserId,
                approvalStatus:approvalStatus
            },
            success: function (res) {
                if (res.code == 0) {
                    layer.msg(res.msg);
                    settlementTable.reload();
                } else {
                    layer.msg(res.msg);
                }
            }
        })
    }
</script>
</body>
</html>


